package com.kfzx.www.animationdemo;

import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class FrameAnimationActivity extends AppCompatActivity {
    private ImageView mImageView;
    private AnimationDrawable mAnimationDrawable;
    private Button mButton1, mButton2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame_animation);
        mButton1 = (Button) findViewById(R.id.start);
        mButton2 = (Button) findViewById(R.id.stop);

        mImageView = (ImageView) findViewById(R.id.image_view);
        mImageView.setBackgroundResource(R.drawable.my_frame_animation);
        mAnimationDrawable = (AnimationDrawable) FrameAnimationActivity.this.mImageView.getBackground();

        mButton1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mAnimationDrawable.start();
            }

        });
        mButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mAnimationDrawable.stop();
            }
        });

    }
}
